//
//  TestViewController.swift
//  DemoTest
//
//  Created by Six on 2017-08-03.
//  Copyright © 2017 Haven. All rights reserved.
//

import UIKit

class TestViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        let nib = UINib(nibName: "TestTableViewCell", bundle: nil)
        self.tableView.register(nib, forCellReuseIdentifier: "TestTableViewCell")
        self.title = "Test";
        self.tableView.estimatedRowHeight = 44
        tableView.rowHeight = UITableViewAutomaticDimension
        
        configNavigation()
    }
    
    func configNavigation() -> Void {
        let item = UIBarButtonItem(title: "DD", style: .plain, target: self, action: #selector(TestViewController.dd))
        self.navigationItem.rightBarButtonItem = item
    }
    
    func dd() {
        print("test")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBOutlet weak var tableView: UITableView!


    //MARK: UITableViewDataSource
    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    
    @available(iOS 2.0, *)
    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "TestTableViewCell", for: indexPath) as! TestTableViewCell
        let image = UIImage(named: "abc")
        if indexPath.row % 2 == 0 {
            cell.headerView.image = image?.imageFlippedForRightToLeftLayoutDirection()
        }
        else {
            cell.headerView.image = image
        }
        return cell
    }
}
